#!/bin/bash

currentoutputfie=run.xml
folderoutputfie=folderruns.xml
globaloutputfile=globalruns.xml

if [ ! -f $globaloutputfile ]; then
    touch $globaloutputfile
fi

cd $1

if [ ! -f $currentoutputfie ]; then
    touch $currentoutputfie
fi
if [ ! -f $folderoutputfie ]; then
    touch $folderoutputfie
fi

folder="<folder>"$1"</folder>\n"
datetag="<enddate>"`date`"</enddate>\n"
xmlblock="<MGrun>\n""$folder""$datetag""</MGrun>"

#./bin/generate -f  --laststep=parton
echo -e "$xmlblock"  >> "$currentoutputfie"
echo -e "$xmlblock"  >> "$folderoutputfie"
cd -

while [ -! `lockfile -1 log.lock` ]; do
    echo -e "accessing file at "`date`
    echo -e "$xmlblock"  >> "$globaloutputfile"
    rm -f log.lock
    break    
done
